package com.woniu.user.configuration;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfiguration {

    private static final String REGISTER_QUEUE = "register_queue";

    private static final String REGISTER_EXCHANGE = "register_exchange";

    private static final String REGISTER_ROUTING = "register_routing";

    @Bean(name = REGISTER_QUEUE)
    public Queue registerQueue(){
        return QueueBuilder.durable(REGISTER_QUEUE).build();
    }

    @Bean(name = REGISTER_EXCHANGE)
    public Exchange registerExchange(){
        return ExchangeBuilder.directExchange(REGISTER_EXCHANGE).build();
    }

    @Bean
    public Binding normalBinding(@Qualifier(REGISTER_QUEUE) Queue queue,
                                 @Qualifier(REGISTER_EXCHANGE) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(REGISTER_ROUTING).noargs();
    }

}
